package com.example.demo.utils;


import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;

public class TokenUtils {
    /**
     * 生成token
     * @return
     */
    public static String genToken(String userId,String sign){
        String token = JWT.create().withAudience(userId) //header
                .withClaim("userId", 21)//payload
                .withClaim("username", "zuhao")//payload
                .withExpiresAt(DateUtil.offsetHour(new Date(),2))//指定令牌的过期时间
                .sign(Algorithm.HMAC256(sign));//签名
        return token;
    }
}
